home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / perl40_2.zip / CMD.H < prev    next >
C/C++ Source or Header  |  1991-11-28  |  5KB  |  185 lines

  1. /* $RCSfile: cmd.h,v $$Revision: 4.0.1.1 $$Date: 91/06/07 10:28:50 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    cmd.h,v $
  9.  * Revision 4.0.1.1  91/06/07  10:28:50  lwall
  10.  * patch4: new copyright notice
  11.  * patch4: length($`), length($&), length($') now optimized to avoid string copy
  12.  *
  13.  * Revision 4.0  91/03/20  01:04:34  lwall
  14.  * 4.0 baseline.
  15.  *
  16.  */
  17.  
  18.  
  19. #define C_NULL 0
  20. #define C_IF 1
  21. #define C_ELSE 2
  22. #define C_WHILE 3
  23. #define C_BLOCK 4
  24. #define C_EXPR 5
  25. #define C_NEXT 6
  26. #define C_ELSIF 7    /* temporary--turns into an IF + ELSE */
  27. #define C_CSWITCH 8    /* created by switch optimization in block_head() */
  28. #define C_NSWITCH 9    /* likewise */
  29.  
  30.  
  31. #ifdef DEBUGGING
  32. #ifndef DOINIT
  33. extern char *cmdname[];
  34. #else
  35. char *cmdname[] = {
  36.     "NULL",
  37.     "IF",
  38.     "ELSE",
  39.     "WHILE",
  40.     "BLOCK",
  41.     "EXPR",
  42.     "NEXT",
  43.     "ELSIF",
  44.     "CSWITCH",
  45.     "NSWITCH",
  46.     "10"
  47. };
  48. #endif
  49. #endif /* DEBUGGING */
  50.  
  51.  
  52. #define CF_OPTIMIZE 077    /* type of optimization */
  53. #define CF_FIRSTNEG 0100/* conditional is ($register NE 'string') */
  54. #define CF_NESURE 0200    /* if short doesn't match we're sure */
  55. #define CF_EQSURE 0400    /* if short does match we're sure */
  56. #define CF_COND    01000    /* test c_expr as conditional first, if not null. */
  57.             /* Set for everything except do {} while currently */
  58. #define CF_LOOP 02000    /* loop on the c_expr conditional (loop modifiers) */
  59. #define CF_INVERT 04000    /* it's an "unless" or an "until" */
  60. #define CF_ONCE 010000    /* we've already pushed the label on the stack */
  61. #define CF_FLIP 020000    /* on a match do flipflop */
  62. #define CF_TERM 040000    /* value of this cmd might be returned */
  63. #define CF_DBSUB 0100000 /* this is an inserted cmd for debugging */
  64.  
  65.  
  66. #define CFT_FALSE 0    /* c_expr is always false */
  67. #define CFT_TRUE 1    /* c_expr is always true */
  68. #define CFT_REG 2    /* c_expr is a simple register */
  69. #define CFT_ANCHOR 3    /* c_expr is an anchored search /^.../ */
  70. #define CFT_STROP 4    /* c_expr is a string comparison */
  71. #define CFT_SCAN 5    /* c_expr is an unanchored search /.../ */
  72. #define CFT_GETS 6    /* c_expr is <filehandle> */
  73. #define CFT_EVAL 7    /* c_expr is not optimized, so call eval() */
  74. #define CFT_UNFLIP 8    /* 2nd half of range not optimized */
  75. #define CFT_CHOP 9    /* c_expr is a chop on a register */
  76. #define CFT_ARRAY 10    /* this is a foreach loop */
  77. #define CFT_INDGETS 11    /* c_expr is <$variable> */
  78. #define CFT_NUMOP 12    /* c_expr is a numeric comparison */
  79. #define CFT_CCLASS 13    /* c_expr must start with one of these characters */
  80. #define CFT_D0 14    /* no special breakpoint at this line */
  81. #define CFT_D1 15    /* possible special breakpoint at this line */
  82.  
  83.  
  84. #ifdef DEBUGGING
  85. #ifndef DOINIT
  86. extern char *cmdopt[];
  87. #else
  88. char *cmdopt[] = {
  89.     "FALSE",
  90.     "TRUE",
  91.     "REG",
  92.     "ANCHOR",
  93.     "STROP",
  94.     "SCAN",
  95.     "GETS",
  96.     "EVAL",
  97.     "UNFLIP",
  98.     "CHOP",
  99.     "ARRAY",
  100.     "INDGETS",
  101.     "NUMOP",
  102.     "CCLASS",
  103.     "14"
  104. };
  105. #endif
  106. #endif /* DEBUGGING */
  107.  
  108.  
  109. struct acmd {
  110.     STAB    *ac_stab;    /* a symbol table entry */
  111.     ARG        *ac_expr;    /* any associated expression */
  112. };
  113.  
  114.  
  115. struct ccmd {
  116.     CMD        *cc_true;    /* normal code to do on if and while */
  117.     CMD        *cc_alt;    /* else cmd ptr or continue code */
  118. };
  119.  
  120.  
  121. struct scmd {
  122.     CMD        **sc_next;    /* array of pointers to commands */
  123.     short    sc_offset;    /* first value - 1 */
  124.     short    sc_max;        /* last value + 1 */
  125. };
  126.  
  127.  
  128. struct cmd {
  129.     CMD        *c_next;    /* the next command at this level */
  130.     ARG        *c_expr;    /* conditional expression */
  131.     CMD        *c_head;    /* head of this command list */
  132.     STR        *c_short;    /* string to match as shortcut */
  133.     STAB    *c_stab;    /* a symbol table entry, mostly for fp */
  134.     SPAT    *c_spat;    /* pattern used by optimization */
  135.     char    *c_label;    /* label for this construct */
  136.     union ucmd {
  137.     struct acmd acmd;    /* normal command */
  138.     struct ccmd ccmd;    /* compound command */
  139.     struct scmd scmd;    /* switch command */
  140.     } ucmd;
  141.     short    c_slen;        /* len of c_short, if not null */
  142.     VOLATILE short c_flags;    /* optimization flags--see above */
  143.     HASH    *c_stash;    /* package line was compiled in */
  144.     STAB    *c_filestab;    /* file the following line # is from */
  145.     line_t      c_line;         /* line # of this command */
  146.     char    c_type;        /* what this command does */
  147. };
  148.  
  149.  
  150. #define Nullcmd Null(CMD*)
  151. #define Nullcsv Null(CSV*)
  152.  
  153.  
  154. EXT CMD * VOLATILE main_root INIT(Nullcmd);
  155. EXT CMD * VOLATILE eval_root INIT(Nullcmd);
  156.  
  157.  
  158. EXT CMD compiling;
  159. EXT CMD * VOLATILE curcmd INIT(&compiling);
  160. EXT CSV * VOLATILE curcsv INIT(Nullcsv);
  161.  
  162.  
  163. struct callsave {
  164.     SUBR *sub;
  165.     STAB *stab;
  166.     CSV *curcsv;
  167.     CMD *curcmd;
  168.     ARRAY *savearray;
  169.     ARRAY *argarray;
  170.     long depth;
  171.     int wantarray;
  172.     char hasargs;
  173. };
  174.  
  175.  
  176. struct compcmd {
  177.     CMD *comp_true;
  178.     CMD *comp_alt;
  179. };
  180.  
  181.  
  182. void opt_arg();
  183. ARG* evalstatic();
  184. int cmd_exec();
  185.